using UnityEngine;
using System.Collections;

public class CharacterStateUncovering : CharacterState
{
	float m_fSpeed = 10.0f;
	float m_fDistanceToGetThere = 0.2f;
	float m_fSeparationFromCover = 1.0f;
	
	public override void enter()
	{
		Vector3 vTargetPos = c.getMiddlePos() + (c.vTargetNormal * m_fSeparationFromCover);
		Vector3 vGroundPos = c.getGroundOfPoint(vTargetPos);
		c.vTargetPosition = vGroundPos;
	}
	
	public override void update()
	{	
		Vector3 vMove = c.vTargetPosition - c.getPos();
		
		// check if character arrived
		if (vMove.magnitude < m_fDistanceToGetThere)
		{
			c.oController.Move(vMove);
			c.changeState<CharacterStateStanding>();
		}
		else
		{
			vMove.Normalize();
			vMove *= m_fSpeed * Time.deltaTime;
			c.oController.Move(vMove);
		}
		
		c.updateVerticalPosition();
		
		if (!c.hasMoved())
		{
			c.changeState<CharacterStateStanding>();
		}
	}
	
	public override void exit()
	{
	}
}
